<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 要求从数据中随机选出3-4个游戏

        const arr = ['英雄联盟', '王者荣耀', '绝地求生', '云顶之弈', 'jj斗地主', '连连看']
        // Math.random() 0~1的数字
        let count = Math.round(Math.random() + 3) // 得到一个3或者4的整数
        var games = [] // 用来收集随机出来的游戏
        function getGames() { // 递归
            let i = Math.round(Math.random()*(arr.length - 1)) // 随机一个商品的下标
            // console.log(arr[i]);
            if(games.includes(arr[i])) {
                getGames()
            } else {
                games.push(arr[i])
                if(games.length < count) {
                    getGames()
                } 
            }
        }
        getGames()
        // console.log(games);
       

    </script>
</body>
</html>